﻿//************************************************************
// Scrum.Net
//************************************************************

using System;
using System.Collections.Generic;
using System.Windows.Input;
using Scrum.Net.Classes;
using Scrum.Net.Interfaces;
using Scrum.Net.Utilities;
using Scrum.Net.Utilities.Commands;

namespace Scrum.Net.ViewModels
{
    public class MainViewModel : ObservableObject, IViewModel 
    {
        private IProject _project;

        public ServiceManager Service;

        private RelayCommand _openProjectCommand;
        private RelayCommand _closeProjectCommand;
        private RelayCommand _newProjectCommand;

        public IViewModel ProjectViewModel {get; set;}

        #region Commands
        public ICommand OpenProjectCommand
        {
            get { return _openProjectCommand ?? (_openProjectCommand = new RelayCommand(OpenProject, () => !Service.IsProjectLoaded)); }
        }

        public ICommand NewProjectCommand
        {
            get { return _newProjectCommand ?? (_newProjectCommand = new RelayCommand(NewProject, () => !Service.IsProjectLoaded)); }
        }

        public ICommand CloseProjectCommand
        {
            get { return _closeProjectCommand ?? (_closeProjectCommand = new RelayCommand(CloseProject, () => Service.IsProjectLoaded)); }
        }
        #endregion

        public IProject Project
        {
            get
            {
                return _project;
            }
            
            set
            {
                _project = value;
                RaisePropertyChanged("Project");
            }
        }

        public MainViewModel()
        {
            Service = new ServiceManager();

            Project = new Project("Test");
            Project.Description = "Test Project for UI Tests";
            Project.Start = DateTime.Today;
            Project.End = DateTime.Today + TimeSpan.FromDays(30);

            ProjectViewModel = new ProjectViewModel(_project, Service);

            Service.IsProjectLoaded = true;
        }

        public void OpenProject()
        {
            Service.IsProjectLoaded = true;
        }

        public void CloseProject()
        {
            Service.IsProjectLoaded = false;
        }

        public void NewProject()
        {
            Project = new Project("New Project");

            Service.IsProjectLoaded = true;
        }

        public void SaveProject(string fileName)
        {
            List<string> projectFiles = new List<string>();

            ZipHelper.Zip(projectFiles, fileName);
        }
    }
}
